<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>

<%@include file="/views/inc/taglib.inc"%>
<link href="${HomeUrl}/views/css/qedit.css" rel="stylesheet" type="text/css" />
<%@ taglib uri="vote/taglib" prefix="vote"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@include file="/views/inc/static.inc"%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>问卷</title>
</head>
<body>
	<%@include file="/views/inc/user.inc"%>
	<br />
	<img src='${HomeUrl}/views/images/logo.jpg' width="1000" />
	<div class="body">
	<%@include file="/views/inc/msgbox.inc" %>

<%@include file="/views/inc/grouplist.inc" %>
		<div class="leftpanel">
			<div class="questionnaire">
				<form action="updateQuestionnaire" method="post" name="questionnaire">
				<div id="questionnaire_display_panel">
				<div id="dqnHead">问卷标题：
				<h2>${questionnaire.questionnaireName }</h2>
				<h3>${questionnaire.questionnaireDescription }</h3>
				</div>
				<input type="hidden" name="questionnaireId" id="questionnaireId"
					value="${questionnaire.questionnaireId }" /> <input type="hidden"
					name="questionCount" value="${fn:length(questionnaire.questionList) }" />
				<div id="dqList"><c:forEach var="item1"
					items="${questionnaire.questionList}" varStatus="status1">
					<div class="dqNode">
					<div class="dqTitle">问题${status1.count }:${item1.questionTitle }</div>
					<input type="hidden" name="questionId-${status1.count }"
						value="${item1.questionId }" /> <c:if test="${item1.questionType==1}">
						<input type="hidden" name="type-${status1.count }"
							value="${item1.questionType }" />
						<div class="doList"><c:forEach var="item2"
							items="${item1.optionList}" varStatus="status">
							<div class="optionClass">${status.count }:<input type="radio"
								name="radioOption-${status1.count }" value="${item2.optionId }" />
							${item2.optionText }</div>
						</c:forEach></div>
					</c:if> <c:if test="${item1.questionType!=1}">
						<input type="hidden" name="type-${status1.count }"
							value="${item1.questionType }" />
						<input type="hidden" name="check-${status1.count }"
							value="${fn:length(item1.optionList) }" />
						<div class="doList"><c:forEach var="item2"
							items="${item1.optionList}" varStatus="status">
							<div class="optionClass">${status.count }:<input
								type="checkbox"
								name="checkOption-${status1.count }-${status.count }"
								value="${item2.optionId }" /> ${item2.optionText }</div>
						</c:forEach></div>
					</c:if></div>
				</c:forEach></div>
				</div>
				<input type="submit" name="提交答案" value="提交答案" /></form>
			</div>
			<h2>评论：<br />
			</h2>
			<div class="commentList replies">
				<c:forEach var="item" items="${questionnaire.commentList}" varStatus="status">
				<div class="commentItem">
				<div class="from_user_id">${item.fromUserName }    <span class="time"><fmt:formatDate value="${item.commentTime}" pattern="yyyy-MM-dd HH:mm" type="both"/></span>
				<input type="button" class="qbutton" value="回复" onclick="getReply({toUserId:${item.fromUserId },toUserName:'${item.toUserName }'})" name="回复"/>
				</div> 
				<c:if test="${item.toUserId!=questionnaire.ownerId}">
				回复${item.toUserName }: 
				</c:if>
				${item.commentText }
				</div>
				</c:forEach>
				
			</div>
			<div>
				<textarea rows="2" cols="50" name="comment_test" id="comment_test"></textarea>
				<input type="hidden" name="toUserId_static" id="toUserId_static" value="${questionnaire.ownerId }"/>
				<input type="hidden" name="toUserId_useful" id="toUserId_useful" value="${questionnaire.ownerId }"/>
				<input type="hidden" name="toUserName_static" id="toUserName_static" value="${questionnaire.ownerName }"/>
				<input type="hidden" name="toUserName_useful" id="toUserName_useful" value="${questionnaire.ownerName }"/>
				                                                                                            
				<input type="button" name="publish" value="发布" class="publish_comment qbutton" id="publish_comment"/>
				</div>
			<div class="result">
				<h2>${questionnaire.questionnaireName }</h2>
				<br />
				<c:forEach var="item1" items="${questionnaire.questionList}"
					varStatus="status">
					<div class="option_title">
					<h1>${status.count }:${item1.questionTitle }</h1>
					</div>
					<c:set var="total" value="0"></c:set>
					<c:forEach var="item2" items="${item1.optionList}" varStatus="status">
						<c:set var="total" value="${ total+item2.optionCount}"></c:set>
					</c:forEach>
					<table class="common-table">
						<tr>
							<th width="300"></th>
							<th width="200"></th>
							<th>百分比</th>
							<th>回答数</th>
						</tr>
						<c:forEach var="item2" items="${item1.optionList}" varStatus="status">
							<tr>
								<c:if test="${total==0}">
									<td>${status.count }:${item2.optionText }</td>
									<td><img src='${HomeUrl}/views/images/bar.gif' height="20"
										width="0" /></td>
									<td>0%</td>
									<td>0</td>
								</c:if>
								<c:if test="${total!=0}">
									<td>${status.count }:${item2.optionText }</td>
									<td><img src='${HomeUrl}/views/images/bar.gif' height="20"
										width="${(item2.optionCount/total)*200 }" /></td>
									<td>${ fn:substring((item2.optionCount/total)*100,0,4)}</td>
									<td>${item2.optionCount }</td>
								</c:if>
							</tr>
						</c:forEach>
					</table>
				</c:forEach>
			</div>
		</div>
		<div class="rightpanel">
			<div class="hotandlast_questionnaire">
			<%@include file="/views/inc/hotandlastest.inc"%></div>
		</div>
		<div class="none"></div>
		<%@include file="/views/inc/copyright.inc" %>
	</div>
	<script type="text/javascript" src="views/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">

   function getReply(toUserId)
   { 
       document.getElementById("toUserId_useful").value = toUserId.toUserId;
       document.getElementById("toUserName_useful").value = toUserId.toUserName;   
         
   }
   
   
    $(function(){
    
    $("#publish_comment").click(function()
    {
       var toUserId=$("#toUserId_useful").val();
       var commentInfo=$("#comment_test").val();
       var questionnaireId=$("#questionnaireId").val();                
       if(commentInfo.length>0)
       {
	      $.post("addComment",{toUserId:toUserId,commentText:commentInfo,questionnaireId:questionnaireId}
	      ,function(r)
	      {
	          if(r.code==1)    
	            {
	              
	               alert("评论成功！！！");
	               var commentList=$(".commentList");
	               var commentItem=$("<div class='commentItem'>");
	               var fromUserName=$("#userNameInfo").text();           
	               var toUserName=$("#toUserName_useful").val();              
	               $("<div class='from_user_id'>"+fromUserName+"<span class='time'>"+r.time+"</span> <input type='button' class='qbutton' value='回复'  name='回复'/></div> ").appendTo(commentItem);
				if($("#toUserName_useful").val()==$("#toUserName_static").val())				
				$("<span>"+commentInfo+"</span>").appendTo(commentItem);
				else
				$("<span>回复："+toUserName+" "+commentInfo+"</span>").appendTo(commentItem);
				commentItem.appendTo(commentList);
				document.getElementById("toUserId_useful").value = $("#toUserId_static").val();
	               document.getElementById("toUserName_useful").value =$("#toUserName_static").val();  
				
	             }
	       else
	       alert("网络错误，评论不成功,请稍后再试");
	      },"json");
       }
       else
       {
         alert("评论内容不能为空！！！");
       }
    });
    });
</script>
		
	
</body>
</html>